package com.dcbeida.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.utils.Utils;

import butterknife.Bind;
import butterknife.ButterKnife;

public class TipDialog extends Dialog {

    @Bind(R.id.tv_ikonw)
    TextView tv_ikonw;

    @Bind(R.id.tv_detail)
    TextView tv_detail;


    private IKonowListener listener;

    private String message;

    private Context mContext;

    private int colorId;

    public TipDialog(@NonNull Context context) {
        super(context, R.style.processDialog);
        mContext=context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_tip2);
        ButterKnife.bind(this);
        setWindow();
    }

    private void setWindow() {
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = Utils.setDisplayMetricsWidth((Activity) mContext) - Utils.convertDip2Pixel(60);
        lp.height = Utils.convertDip2Pixel(150);
        window.setGravity(Gravity.CENTER);
        window.setAttributes(lp);
        setCancelable(true);
        tv_ikonw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener != null)
                    listener.iKown();
                dismiss();
            }
        });
        setData();
    }

    public void setListener(IKonowListener listener){
        this.listener =listener;
    }

    private void setData() {
        if (!TextUtils.isEmpty(message)) {
            tv_detail.setText(message);
        }
        if(colorId>0){
            tv_detail.setTextColor(mContext.getResources().getColor(colorId));
        }
    }

    public TipDialog setMessage(String message) {
        this.message = message;
        return this;
    }

    public TipDialog setTxColor(int colorId){
        this.colorId=colorId;
        return this;
    }

    @Override
    public void show() {
        super.show();
    }

    public interface  IKonowListener{
        void iKown();
    }
}
